#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_QtCommonComponet.h"
#include <QTCPSocket>
#include <QTCPServer>
#include <QSound>

#include "GVerifyCode/verifycodewidget.h"
#include "Sqlite/BaseSqliteHelper.h"
#include "HTTP/qnetworkhttpclient.h"
#include "HTTP/qnetworkhttpserver.h"
#include "HTTP/protocol.h"
#include "comSerialPort/ComDeviceControl.h"
#include "comSerialPort/TcpClient.h"
#include "MultiThread/xxManager.h"
#include "showModal/dialogtip.h"
#include "showModal/MaterialDesignIcons.h"
#include "MySQLHelper/DBControl.h"
#include "MySQLHelper/ConnMySqHelper.h"
#include "TagPrint/TagPrintControl.h"


QT_BEGIN_NAMESPACE
namespace Ui { class QtCommonComponetClass; };
QT_END_NAMESPACE

class QtCommonComponet : public QMainWindow
{
    Q_OBJECT

public:
    QtCommonComponet(QWidget *parent = nullptr);
    ~QtCommonComponet();

    void InitVerifyCodeWidget();

    void initDB();
    void initMysqlDB(); 

    void initHttpClient();
    void initHttpServer();

    void initComSerialPort();
    void initMultiThreadFramework();

    void initTCPServer();
    void stopServer();

    void initTCPClient();

    void appendLog(const QString& logmessage);

    void messageTipShow(const QString& msg);
public slots:
    void slot_pushButtonVerfyCode();
    void slot_connStateChange(int state);
    void slot_reciveSerialPortData(const QString& data);
    void slot_comportIndexChanged(int index);
    void slot_showMessageBox();

    void slot_newConnection();
    void slot_disconnected();
    void slot_reciveData();

    void slot_newConnectionClient();
    void slot_getDataFromServer();
    void slot_disconnectedClient();
    void slot_sendData();

    void slot_soundPlay();

    void slot_printTag();

private:
    Ui::QtCommonComponetClass *ui;

    VerifyCodeWidget* verifyCodeWidget;
    QSharedPointer<BaseSqliteHelper>    m_data_db;
    QSharedPointer<DBControl>    m_mysqlData_db;

    QSharedPointer<QNetworkHttpClient> m_httpClient;
    std::shared_ptr<QNetworkHttpServer> m_httpServer;

    QTcpServer m_server;
    QSet<QTcpSocket*> m_clientSockets;
    QTcpSocket* m_clientSocket;
    QSharedPointer<CommonComponet::TcpClient> m_binaryClient;


    CommonComponet::ComDeviceControl* m_pComDevice = NULL;
    QString    m_scan_com_name;

    QSound* m_bell;

    TagPrintControl* m_pTagPrintControl = NULL;
    QString                m_print_device;
    QString m_printContent;

};
